import * as Cesium from 'cesium';
//@ts-ignore
const { VertexAttributeSemantic, DeveloperError, defined } = Cesium;
export const VertexAttributeSemanticGaussian = {
    ...VertexAttributeSemantic,
    SCALE: "_SCALE",
    ROTATION: "_ROTATION",
    getGlslType: function (semantic: any) {
        //>>includeStart('debug', pragmas.debug);
        Cesium.Check.typeOf.string("semantic", semantic);
        //>>includeEnd('debug');
        switch (semantic) {
            case VertexAttributeSemanticGaussian.POSITION:
            case VertexAttributeSemanticGaussian.NORMAL:
            case VertexAttributeSemanticGaussian.TANGENT:
                return "vec3";
            case VertexAttributeSemanticGaussian.TEXCOORD:
                return "vec2";
            case VertexAttributeSemanticGaussian.COLOR:
                return "vec4";
            case VertexAttributeSemanticGaussian.JOINTS:
                return "ivec4";
            case VertexAttributeSemanticGaussian.WEIGHTS:
                return "vec4";
            case VertexAttributeSemanticGaussian.FEATURE_ID:
                return "int";
            case VertexAttributeSemanticGaussian.SCALE:
                return "vec3";
            case VertexAttributeSemanticGaussian.ROTATION:
                return "vec4";
            //>>includeStart('debug', pragmas.debug);
            default:
                throw new DeveloperError("semantic is not a valid value.");
            //>>includeEnd('debug');
        }
    },
    hasSetIndex: function (semantic: any) {
        //>>includeStart('debug', pragmas.debug);
        Cesium.Check.typeOf.string("semantic", semantic);
        //>>includeEnd('debug');

        switch (semantic) {
            case VertexAttributeSemanticGaussian.POSITION:
            case VertexAttributeSemanticGaussian.NORMAL:
            case VertexAttributeSemanticGaussian.TANGENT:
                return false;
            case VertexAttributeSemanticGaussian.TEXCOORD:
            case VertexAttributeSemanticGaussian.COLOR:
            case VertexAttributeSemanticGaussian.JOINTS:
            case VertexAttributeSemanticGaussian.WEIGHTS:
            case VertexAttributeSemanticGaussian.FEATURE_ID:
            case VertexAttributeSemanticGaussian.SCALE:
            case VertexAttributeSemanticGaussian.ROTATION:
                return true;
            //>>includeStart('debug', pragmas.debug);
            default:
                throw new DeveloperError("semantic is not a valid value.");
            //>>includeEnd('debug');
        }
    },
    getVariableName: function (semantic: any, setIndex: any) {
        //>>includeStart('debug', pragmas.debug);
        Cesium.Check.typeOf.string("semantic", semantic);
        //>>includeEnd('debug');

        let variableName = semanticToVariableName(semantic);
        if (defined(setIndex)) {
            variableName += `_${setIndex}`;
        }
        return variableName;
    },
    fromGltfSemantic: function (gltfSemantic: any) {
        //>>includeStart('debug', pragmas.debug);
        Cesium.Check.typeOf.string("gltfSemantic", gltfSemantic);
        //>>includeEnd('debug');

        let semantic = gltfSemantic;

        // Strip the set index from the semantic
        const setIndexRegex = /^(\w+)_\d+$/;
        const setIndexMatch = setIndexRegex.exec(gltfSemantic);
        if (setIndexMatch !== null) {
            semantic = setIndexMatch[1];
        }

        switch (semantic) {
            case "POSITION":
                return VertexAttributeSemanticGaussian.POSITION;
            case "NORMAL":
                return VertexAttributeSemanticGaussian.NORMAL;
            case "TANGENT":
                return VertexAttributeSemanticGaussian.TANGENT;
            case "TEXCOORD":
                return VertexAttributeSemanticGaussian.TEXCOORD;
            case "COLOR":
                return VertexAttributeSemanticGaussian.COLOR;
            case "JOINTS":
                return VertexAttributeSemanticGaussian.JOINTS;
            case "WEIGHTS":
                return VertexAttributeSemanticGaussian.WEIGHTS;
            case "_FEATURE_ID":
                return VertexAttributeSemanticGaussian.FEATURE_ID;
            case "_SCALE":
                return VertexAttributeSemanticGaussian.SCALE;
            case "_ROTATION":
                return VertexAttributeSemanticGaussian.ROTATION;
        }

        return undefined;
    }
}
function semanticToVariableName(semantic: any) {
    switch (semantic) {
        case VertexAttributeSemanticGaussian.POSITION:
            return "positionMC";
        case VertexAttributeSemanticGaussian.NORMAL:
            return "normalMC";
        case VertexAttributeSemanticGaussian.TANGENT:
            return "tangentMC";
        case VertexAttributeSemanticGaussian.TEXCOORD:
            return "texCoord";
        case VertexAttributeSemanticGaussian.COLOR:
            return "color";
        case VertexAttributeSemanticGaussian.JOINTS:
            return "joints";
        case VertexAttributeSemanticGaussian.WEIGHTS:
            return "weights";
        case VertexAttributeSemanticGaussian.FEATURE_ID:
            return "featureId";
        case VertexAttributeSemanticGaussian.SCALE:
            return "scale";
        case VertexAttributeSemanticGaussian.ROTATION:
            return "rotation";
        //>>includeStart('debug', pragmas.debug);
        default:
            throw new DeveloperError("semantic is not a valid value.");
        //>>includeEnd('debug');
    }
}